package com.nms.model;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
/**
 * 用户
 * 
 * @author Administrator
 *
 */
@Entity
@Table(name="t_user")
public class User{

	private String id;
	/** 用户账户 */
	private String username;
	/** 用户密码 */
	private String password;
	/** 账号属性（会员或普通用户）0为普通用户*/
	private Integer property;
	/** 用户等级*/
	private Integer grade;
	/** 用户*/
	private String homepage;
	/** 用户角色集合*/
	private Set<Role> roles;
	/** 用户状态（是否激活<1>，是否停用<-1>，或暂时停用<0>）*/
	private Integer state;
	/** 用户昵称 */
	private String nickname;
	/** 注册时间*/
	private Date registerTime;
	private UserInfo userInfo;

	private Role role;
	@Id
	@Column(name="id",length=64)
	@GeneratedValue(generator="uuid")
	@GenericGenerator(name="uuid",strategy="uuid")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name="username",nullable=false,unique=true,updatable=false,length=32)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username){
		this.username = username;
	}
	
	/**
	 * 获得用户密码
	 * @return
	 */
	@Column(name="password",length=64,nullable=false)
	public String getPassword() {
		return password;
	}
	
	/**
	 * 设置用户密码
	 * @param password
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	
	@Column
	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}


	@Column(name="register_time")
	public Date getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}


	@Column
	public Integer getProperty() {
		return property;
	}

	public void setProperty(Integer property) {
		this.property = property;
	}

	@Column
	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	/**
	 * (扩展多角色是在实现，目前使用单角色模式)
	 * 获得用户的角色集合
	 * 通过代码获得角色集合
	 * @return
	 */
	@Transient
	public Set<Role> getRoles() {
		return roles;
	}

	/**
	 * 设置用户角色集合
	 * @param authority
	 */
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@OneToOne(targetEntity=Role.class,fetch=FetchType.EAGER)
	@JoinColumn(name="role_id", referencedColumnName="id")
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Column
	public Integer getGrade() {
		return grade;
	}

	public void setGrade(Integer grade) {
		this.grade = grade;
	}

	@Column
	public String getHomepage() {
		return homepage;
	}

	public void setHomepage(String homepage) {
		this.homepage = homepage;
	}

	@OneToOne(targetEntity=UserInfo.class,cascade=CascadeType.ALL)
	@JoinColumn(name="user_info_id",referencedColumnName="id")
	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

}
